package cn.kgc.tangcco.tcbd1011.no13.type.action;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.kgc.tangcco.tcbd1011.no13.base.action.BaseServlet;
import cn.kgc.tangcco.tcbd1011.no13.base.properties.factory.PropertiesFactory;
import cn.kgc.tangcco.tcbd1011.no13.base.util.MyBeanUtils;
import cn.kgc.tangcco.tcbd1011.no13.base.util.Utils;
import cn.kgc.tangcco.tcbd1011.no13.type.entity.Type;
import cn.kgc.tangcco.tcbd1011.no13.type.service.TypeService;
@WebServlet(name="TypeServlet",urlPatterns="/type.action")
public class TypeServlet extends BaseServlet {

	private static final String SUCCESS="type.action?methodName=doListType";
	private TypeService tservice;
	public TypeServlet() {
		tservice=(TypeService) PropertiesFactory.getInstance(Utils.TYPESERVICE);
	}
	
	public String doListType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "type/listType";
		request.setAttribute("tlist", tservice.queryAllType());
		return forward;
	}
//	跳转到添加页面
	public String toAddType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "type/addType";
		
		return forward;
	}
//	添加修改值  返回list页面
	public String doAddType(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		request.setAttribute("rows", tservice.addType(MyBeanUtils.populate(Type.class, request.getParameterMap())));
		
		return forward;
	}
//	查看页面
	public String detailType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "type/detailType";
		request.setAttribute("type", tservice.detatilType(Utils.parseInt(request.getParameter("typeId"))));
		return forward;
	}
//	去添加页面
	public String toUpdateType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "type/updateType";
		request.setAttribute("type", tservice.detatilType(Utils.parseInt(request.getParameter("typeId"))));
		return forward;
	}
//	修改页面修改值，并跳转回list页面
	public String daUpdateType(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		int rows=tservice.updateType(MyBeanUtils.populate(Type.class, request.getParameterMap()));
		request.setAttribute("rows", rows);
		return forward;
	}
//	删除信息
	public String doDeleteType(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		request.setAttribute("rows", tservice.deleteType(Utils.parseInt(request.getParameter("typeId"))));
		return forward;
	}
	
	
	
	
	
	
	
	
}
